import { Component, Input, OnInit } from '@angular/core';
import { Episode, Express, Scene } from 'src/classes/entities';
import { DataService } from 'src/services/data.service';

@Component({
  selector: 'app-episodeview',
  templateUrl: './episodeview.component.html',
  styleUrls: ['./episodeview.component.scss']
})
export class EpisodeviewComponent implements OnInit {

  constructor(private dataservice: DataService) { }

  ngOnInit(): void {
  }
  @Input()
  public get target(): Episode {
    return this.internalTarget;
  }

  public set target(v: Episode) {
    this.internalTarget = v;
    this.scenes = this.dataservice.getScenes(v, this.internalParent)
  }

  private internalTarget: Episode;

  @Input()
  public get parent(): Express {
    return this.internalParent;
  }

  public set parent(v: Express) {
    this.internalParent = v;
  }

  private internalParent: Express;

  @Input()
  public get totalWidth(): number {
    return this.internalTotalWidth;
  }

  public set totalWidth(v: number) {
    this.internalTotalWidth = v;
  }

  private internalTotalWidth: number;

  scenes: Scene[] = []
  public get cwidth(): number {

    let ts = this.internalParent.Episodes.reduce((a, b) => a + b.Spend, 0)
    return this.internalTarget.Spend / ts * this.internalTotalWidth
  }

}
